package com.algorithm.offer.linkedtable;

/**
 * @Author: huangzhigao
 * @Date: 2021/11/8 21:33
 * 反转链表
 * 给定一个单链表的头结点pHead，长度为n，反转该链表后，返回新链表的表头。
 */
public class JZ24 {
    public ListNode ReverseList(ListNode head) {
        if (null == head) {
            return null;
        }

        ListNode dummyNode = null;
        while (null != head) {
            ListNode curHead = head.next;
            head.next = dummyNode;
            dummyNode = head;
            head = curHead;
        }
        return dummyNode;
    }
}

class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}
